﻿Public Class clsFLBinfo
    Public Function getFlbInfoBySysId(sys_id As String) As DataTable
        Dim szSql As String = "SELECT * FROM sf.b_flb_info WHERE sys_id = ? "
        Return DBacs.ExecuteSql(szSql, -1, sys_id)
    End Function

    Public Function updateWhichSideBySysId(which_side As String, sys_id As String) As Integer
        Dim szSql As String = "update sf.b_flb_info set which_side = ? where sys_id = ? "
        Return DBacs.ExecuteUpdateSql(szSql, -1, which_side, sys_id)
    End Function

    Public Function save(piece_num As String, used_piece_num As String, sys_id As String) As Integer
        Dim szSql As String
        Dim rtn As Integer = -2
        Dim piece_num_integer As Integer = Integer.Parse(piece_num)
        Dim used_piece_num_integer As Integer = Integer.Parse(used_piece_num)
        If used_piece_num_integer = 0 Then
            szSql = "update sf.b_flb_info set used_piece_num = ?,status = ? where sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, used_piece_num, "0", sys_id)
        End If
        If piece_num_integer > used_piece_num_integer Then
            szSql = "update sf.b_flb_info set used_piece_num = ?,status = ? where sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, used_piece_num, "1", sys_id)
        End If
        If piece_num_integer = used_piece_num_integer Then
            szSql = "update sf.b_flb_info set used_piece_num = ?,status = ? where sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, used_piece_num, "2", sys_id)
        End If
        Return rtn
    End Function

    Public Function getFlbInfoByDlNo(dl_no As String) As DataTable
        Dim szSql As String = "SELECT a.*,b.material_code as flb_material_code FROM sf.b_flb_info a left join sf.b_gt b on a.b_gt_sys_id = b.sys_id WHERE a.dl_no = ? and a.piece_num > 0 AND a.status <> '2'"
        Return DBacs.ExecuteSql(szSql, -1, dl_no)
    End Function

    Public Function getFlbInfoUnused() As DataTable
        Dim szSql As String = "SELECT a.*,b.material_code as flb_material_code FROM sf.b_flb_info a left join sf.b_gt b on a.b_gt_sys_id = b.sys_id WHERE 1 = 1 AND a.status <> '2'"
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

End Class
